<?php
define('IN_SCRIPT', 1);
define('HESK_PATH', './');
define('HESK_NO_ROBOTS', 1);

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');

hesk_session_start();

/* Print header */
require_once(HESK_PATH . 'inc/header.inc.php');
?>

<script type="text/javascript">
    var category;
    var current_node;
    
    function loadTopics() {
        $('#topic-select').empty();
        
        var cat = encodeURI($('#category-select').val());
        
        $.get('diag_topics_ajax.php?category=' + cat, function(data) {
            $('#topic-select').append(data);
        });
    }
    
    function startDiagnose() {
        category = encodeURI($('#topic-select').val());
        
        if(child = $('#answer2')){
            child.remove();
        }        
        
        $('#answer1 .diagnose-container').hide();
        $('#answer1').fadeIn('slow');
        $('#answer1 .ajax-loader-container').fadeIn('slow');
       
        $('#answer1 .diagnose-container').load('diagnose_ajax.php?category=' + category + '&question_id=1', function() {
            $('#answer1 .ajax-loader-container').hide();
            $('#answer1 .diagnose-container').fadeIn('slow');
        });
    }
    
    function submitAnswer(question_id,answer) {
        question_id = parseInt(question_id);
        if(child = $('#answer' + (question_id + 1))){
            child.remove();
        }
        
        //duplicate object and append
        var obj = $('#answer' + question_id).clone();
        obj.attr('id','answer' + (question_id + 1));
        obj.appendTo('#answer' + question_id);
        
        question_id += 1;
        $('#answer' + question_id).fadeIn('slow');
        $('#answer' + question_id + ' .ajax-loader-container').fadeIn();
        $('#answer' + question_id + ' .diagnose-container').hide();
        
        $('#answer' + question_id + ' .diagnose-container').load('diagnose_ajax.php?answer=' + answer + '&question_id=' + question_id, function() {
            $('#answer' + question_id + ' .ajax-loader-container').hide();
            $('#answer' + question_id + ' .diagnose-container').fadeIn('slow');
        });
    }
    
    function createObject(number){
        var obj = document.createElement('div');
        obj.attr('id','answer' + number);
        obj.addClass('question');
        obj.addClass('none');
        $('.answer-separator').clone().appendTo(obj);
    }
    
    $(document).ready(function () {
        loadTopics();
    });
</script>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
        <td><span class="smaller"><a href="<?php echo $hesk_settings['site_url']; ?>" class="smaller"><?php echo $hesk_settings['site_title']; ?></a> &gt;
                <a href="<?php echo $hesk_settings['hesk_url']; ?>" class="smaller"><?php echo $hesk_settings['hesk_title']; ?></a>
                &gt; <?php echo $hesklang['start_diagnose']; ?></span></td>
    </tr>
</table>

</td>
</tr>
<tr>
    <td>

        <?php
        /* This will handle error, success and notice messages */
        hesk_handle_messages();

        /* Connect to database */
        hesk_dbConnect();

        /* Get ticket info */
        $sql = "SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "diag_parent_cat`";
        $result = hesk_dbQuery($sql);
        ?>

        <p>&nbsp;</p>

        <div align="center">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="7" height="7"><img src="img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
                    <td class="roundcornerstop"></td>
                    <td><img src="img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
                </tr>
                <tr>
                    <td class="roundcornersleft">&nbsp;</td>
                    <td>
                        <form method="get" action="#">
                            <div id="category-select-container" align="center">
                                <?php echo $hesklang['d_cat']; ?>
                                <select id="category-select" onchange="loadTopics()">
                                    <?php
                                    while ($category = hesk_dbFetchAssoc($result)) {
                                        echo "<option>" . $category["name"] . "</option>";
                                    }
                                    ?>
                                </select>&nbsp;&nbsp;&nbsp;
                                <?php echo $hesklang['d_topic']; ?>
                                <select id="topic-select" onchange="startDiagnose()">
                                </select>&nbsp;&nbsp;&nbsp;
                                <input type="submit" onmouseout="hesk_btn(this,'orangebutton');" onmouseover="hesk_btn(this,'orangebuttonover');" onclick="startDiagnose(); return false;" class="orangebutton" value="<?php echo $hesklang['check']; ?>">
                            </div>
                        </form>
                    </td>
                    <td class="roundcornersright">&nbsp;</td>
                </tr>
                <tr>
                    <td><img src="img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
                    <td class="roundcornersbottom"></td>
                    <td width="7" height="7"><img src="img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
                </tr>
            </table>
            <div id="answer1" align="center" class="question none">
                <div class="answer-separator">
                </div>
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="7" height="7"><img src="img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
                        <td class="roundcornerstop"></td>
                        <td><img src="img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
                    </tr>
                    <tr>
                        <td class="roundcornersleft">&nbsp;</td>
                        <td>
                            <form method="get" action="#">
                                <div class="ajax-loader-container" align="center" style="display:none">
                                    <p>&nbsp;</p>
                                    <img alt="" src="img/ajax-loader.gif" />
                                    <p>&nbsp;</p>
                                </div>
                                <div class="diagnose-container" align="center" style="display:none; width: 400px">
                                    
                                </div>
                            </form>
                        </td>
                        <td class="roundcornersright">&nbsp;</td>
                    </tr>
                    <tr>
                        <td><img src="img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
                        <td class="roundcornersbottom"></td>
                        <td width="7" height="7"><img src="img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
                    </tr>
                </table>
            </div>
        </div>

        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>

        <?php
        require_once(HESK_PATH . 'inc/footer.inc.php');
        ?>
